package com.trafficsys.modules.owner.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trafficsys.modules.entity.TravelCard;
import com.trafficsys.modules.owner.dao.EditCarDao;
import com.trafficsys.modules.owner.service.EditCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
@Service
public class EditCarImpl implements EditCarService {
    @Autowired
    EditCarDao editCarDao;
    /**
     * 车辆上户
     * @param travelCard
     * @return
     */
    @Override
    public HashMap<String, Object> addCar(TravelCard travelCard) {
        HashMap<String,Object> map=new HashMap<>();
        int i=editCarDao.insert(travelCard);
        if(i>0){
            map.put("msg","SUCCESS");
        }else {
            map.put("msg","FAILED");
        }
        return map;
    }

    /**
     * 车辆过户
     * @param travelCard
     * @return
     */
    @Override
    public HashMap<String, Object> updateCar(TravelCard travelCard) {
        HashMap<String,Object> map=new HashMap<>();
        int i=editCarDao.updateCarByTravelCarId(travelCard);
        if(i>0){
            map.put("msg","SUCCESS");
        }else {
            map.put("msg","FAILED");
        }
        return map;
    }



    /**
     * 车辆报废
     * @param travelCarId
     * @return
     */
    @Override
    public HashMap<String, Object> delCar(String travelCarId) {
        HashMap<String,Object> map=new HashMap<>();
        int i=editCarDao.delCarByTravelCarId(travelCarId);
        if(i>0){
            map.put("msg","SUCCESS");
        }else {
            map.put("msg","FAILED");
        }
        return map;
    }

    @Override
    public IPage<TravelCard> getByPage(Integer pageSize, Integer currentPage) {
        QueryWrapper<TravelCard> wrapper = new QueryWrapper<>();
        return editCarDao.selectPage(new Page<>(currentPage, pageSize),wrapper);
    }
}
